<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1 , user-scalable=no">
<title>家庭作业添加</title>
<link href="__PUBLIC__/plugins/bootstrap.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/bootstrap-dashen.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/font-awesome.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/animate.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
</head>
<body style="margin-top:70px;">
{include file="common/header" /}
<div class="container">
	<div class="row">
		<div class="col-md-12 wow fadeInUp" data-wow-duration="0.5s">
			<div>
				<!-- Nav tabs -->
				<ul class="nav nav-tabs" role="tablist">
			    	<li role="presentation" ><a href="{:url('Homework/frontlist')}">家庭作业列表</a></li>
			    	<li role="presentation" class="active"><a href="#homeworkAdd" aria-controls="homeworkAdd" role="tab" data-toggle="tab">添加家庭作业</a></li>
				</ul>
				<!-- Tab panes -->
				<div class="tab-content">
				    <div role="tabpanel" class="tab-pane" id="homeworkList">
				    </div>
				    <div role="tabpanel" class="tab-pane active" id="homeworkAdd"> 
				      	<form class="form-horizontal" name="homeworkAddForm" id="homeworkAddForm" enctype="multipart/form-data" method="post"  class="mar_t15">
						  <div class="form-group">
						  	 <label for="homework_taskTitle" class="col-md-2 text-right">作业任务:</label>
						  	 <div class="col-md-8">
							    <input type="text" id="homework_taskTitle" name="homework_taskTitle" class="form-control" placeholder="请输入作业任务">
							 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="homework_taskContent" class="col-md-2 text-right">作业要求:</label>
						  	 <div class="col-md-8">
							    <textarea name="homework_taskContent" id="homework_taskContent" style="width:100%;height:500px;"></textarea>
							 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="homework_teacherObj_teacherNo" class="col-md-2 text-right">布置的老师:</label>
						  	 <div class="col-md-8">
							    <select id="homework_teacherObj_teacherNo" name="homework.teacherObj.teacherNo" class="form-control">
							    </select>
						  	 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="homework_homeworkDateDiv" class="col-md-2 text-right">作业日期:</label>
						  	 <div class="col-md-8">
				                <div id="homework_homeworkDateDiv" class="input-group date homework_homeworkDate col-md-12" data-link-field="homework_homeworkDate" data-link-format="yyyy-mm-dd">
				                    <input class="form-control" id="homework_homeworkDate" name="homework_homeworkDate" size="16" type="text" value="" placeholder="请选择作业日期" readonly>
				                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
				                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
				                </div>
						  	 </div>
						  </div>
				          <div class="form-group">
				             <span class="col-md-2"></span>
				             <span onclick="ajaxHomeworkAdd();" class="btn btn-primary bottom5 top5">添加</span>
				          </div>
						</form> 
				        <style>#homeworkAddForm .form-group {margin:10px;}  </style>
					</div>
				</div>
			</div>
		</div>
	</div> 
</div>

{include file="common/footer" /}
<script src="__PUBLIC__/plugins/jquery.min.js"></script>
<script src="__PUBLIC__/plugins/bootstrap.js"></script>
<script src="__PUBLIC__/plugins/wow.min.js"></script>
<script src="__PUBLIC__/plugins/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugins/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="__PUBLIC__/plugins/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
//实例化编辑器
var homework_taskContent_editor = UE.getEditor('homework_taskContent'); //作业要求编辑器
	//提交添加家庭作业信息
	function ajaxHomeworkAdd() { 
		//提交之前先验证表单
		$("#homeworkAddForm").data('bootstrapValidator').validate();
		if(!$("#homeworkAddForm").data('bootstrapValidator').isValid()){
			return;
		}
		if(homework_taskContent_editor.getContent() == "") {
			alert('作业要求不能为空');
			return;
		}
		jQuery.ajax({
			type : "post",
			url : "{:url('Homework/frontAdd')}",
			dataType : "json" , 
			data: new FormData($("#homeworkAddForm")[0]),
			success : function(obj) {
				if(obj.success){ 
					alert("保存成功！");
					$("#homeworkAddForm").find("input").val("");
					$("#homeworkAddForm").find("textarea").val("");
					homework_taskContent_editor.setContent("");
				} else {
					alert(obj.message);
				}
			},
			processData: false, 
			contentType: false, 
		});
	} 
$(function(){
	/*小屏幕导航点击关闭菜单*/
    $('.navbar-collapse a').click(function(){
        $('.navbar-collapse').collapse('hide');
    });
    new WOW().init();
	//验证家庭作业添加表单字段
	$('#homeworkAddForm').bootstrapValidator({
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		},
		fields: {
			"homework_taskTitle": {
				validators: {
					notEmpty: {
						message: "作业任务不能为空",
					}
				}
			},
			"homework_homeworkDate": {
				validators: {
					notEmpty: {
						message: "作业日期不能为空",
					}
				}
			},
		}
	}); 
	//初始化布置的老师下拉框值 
	$.ajax({
		url: "{:url('Teacher/listAll')}",
		type: "get",
		dataType: "json",
		success: function(teachers,response,status) { 
			$("#homework_teacherObj_teacherNo").empty();
			var html="";
    		$(teachers).each(function(i,teacher){
    			html += "<option value='" + teacher.teacherNo + "'>" + teacher.teacherName + "</option>";
    		});
    		$("#homework_teacherObj_teacherNo").html(html);
    	}
	});
	//作业日期组件
	$('#homework_homeworkDateDiv').datetimepicker({
		language:  'zh-CN',  //显示语言
		format: 'yyyy-mm-dd',
		minView: 2,
		weekStart: 1,
		todayBtn:  1,
		autoclose: 1,
		minuteStep: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0
	}).on('hide',function(e) {
		//下面这行代码解决日期组件改变日期后不验证的问题
		$('#homeworkAddForm').data('bootstrapValidator').updateStatus('homework_homeworkDate', 'NOT_VALIDATED',null).validateField('homework_homeworkDate');
	});
})
</script>
</body>
</html>
